const ffmpeg = require('fluent-ffmpeg');
const qualityList = ['', '1920x1080', '1280x720', '640x480']
const  circularJSON = require('circular-json');

process.on('message', function (res) {
  console.log(res, global)
  const { filePath, startTime, quality } = JSON.parse(process.argv.pop());
   ffmpeg(`./public/${filePath}`)
  // 支持在线播放
  .outputOptions(['-movflags isml+frag_keyframe'])
  .format("mp4")
  .size(qualityList[quality])
  .seekInput(startTime || '0:0:0.000')
  .on('error', function(err, stdout, stderr) {
    res.end();
    console.log(err.message, stdout, stderr);
  })
  .on('end', function() {
    res.end()
    console.log('Processing finished !');
  })
  .pipe(res, { end: true });
})
